<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Session;
use \think\Db;
class Formpost extends Common
{
	
  public function addpost(){
    $citylist = Db::name('city')->where('city_status',1)->select();
    $communitylist = Db::name('community')->where('community_status',1)->select();
    $this->assign('citylist',$citylist);
    $this->assign('communitylist',$communitylist);
    return $this->fetch();
  }

  public function editpost(){

    $post = Db::name('post')->where('post_id',input('postid'))->find();
    $citylist = Db::name('city')->where('city_status',1)->select();
    $communitylist = Db::name('community')->where('community_status',1)->select();
    $this->assign('post',$post);
    $this->assign('citylist',$citylist);
    $this->assign('communitylist',$communitylist);
    return $this->fetch();

  }

  public function add(){
    $info = '';
     if(request()->isPost()){  
        $data=[
          'city_id'=>input('city'),
          'community_id'=>input('community'),
          'user_id'=>0,
          'post_title'=>input('title'),
          'post_content'=>input('content'),
          'post_time'=>date('Y-m-d H:i:s'),
          'post_commenttime'=>0,
          'post_hit'=>0,
          'post_like'=>0,
          'post_comment'=>0,
          'post_hot'=>0,
          'comment_status'=>1,
          'post_status'=>1,
        ];
        $res=Db::name('post')->insert($data);
        if ($res){
          $this->success("添加帖子成功",'community/post');
        }
        else {
          $this->error("添加失败");
        }
      }
  }



  public function edit(){
    $info = '';
     if(request()->isPost()){  
        $data=[
          'city_id'=>input('city'),
          'community_id'=>input('community'),
          'post_title'=>input('title'),
          'post_content'=>input('content'),
        ];
        $res=Db::name('post')->where('post_id',input('postid'))->update($data);
        if ($res!==false){
          $this->success("修改帖子成功",'community/post');
        }
        else {
          $this->error("修改失败");
        }
      }
  }

  public function delete(){
    $res = Db::name('post')->where('post_id',input('postid'))->update(['post_status'=>input('statu')]);
    if($res===false){
        $this->error("处理失败");
    }
    $this->redirect('community/post');
  }

  
}